package com.sgb.jicai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JcMyFactoryListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;

import java.util.List;

public class JcMyFactoryAdapter extends BaseRecycleAdapter<JcMyFactoryListEntity> {

    private Context context;
    private DeleteListerner deleteListener;

    public JcMyFactoryAdapter(Context context, List<JcMyFactoryListEntity> datas) {
        super(context, R.layout.item_jc_my_factory, datas);
        this.context = context;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView tvStop = holder.itemView.findViewById(R.id.tv_stop);
        TextView tvDelete = holder.itemView.findViewById(R.id.tv_delete);
        tvStop.setOnClickListener(view -> {
            if (null != deleteListener) {
                deleteListener.stopJc(datas.get(position));
            }
        });
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != deleteListener) {
                    deleteListener.DeleteJc(datas.get(position));
                }
            }
        });
    }

    @Override
    public void convert(ItemViewHolder holder, JcMyFactoryListEntity jcMyFactoryListEntity) {
        holder.setBinding(BR.viewModel, jcMyFactoryListEntity);
        TextView tvCreatTime = holder.itemView.findViewById(R.id.tv_create_time);
        tvCreatTime.setText(MDateUtil.getYMDHSDate(jcMyFactoryListEntity.getCreateTime()));
        TextView tvStop = holder.itemView.findViewById(R.id.tv_stop);
       // TextView tvQuit = holder.itemView.findViewById(R.id.tv_quit);
        TextView tvDelete = holder.itemView.findViewById(R.id.tv_delete);
        ImageView ivStatus = holder.itemView.findViewById(R.id.iv_status);
        if (jcMyFactoryListEntity.getStatus().equals("1")) {//集采中
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.collect_ing));
            tvStop.setVisibility(View.VISIBLE);
            tvDelete.setVisibility(View.GONE);
          //  tvQuit.setVisibility(View.GONE);
        } else if (jcMyFactoryListEntity.getStatus().equals("8")){//审批中
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.jc_spz));
            tvStop.setVisibility(View.GONE);
            tvDelete.setVisibility(View.GONE);
        }else if (jcMyFactoryListEntity.getStatus().equals("9")){//已拒绝
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.jc_yjj));
            tvStop.setVisibility(View.GONE);
            tvDelete.setVisibility(View.GONE);
        }else {//集采结束
            ivStatus.setBackground(context.getResources().getDrawable(R.mipmap.collect_complate));
            tvStop.setVisibility(View.GONE);
            tvDelete.setVisibility(View.VISIBLE);
            //tvQuit.setVisibility(View.GONE);
        }
    }

    public interface DeleteListerner {

        void stopJc(JcMyFactoryListEntity entity);
        void DeleteJc(JcMyFactoryListEntity entity);

        //void quitJc(JcMyFactoryListEntity entity);
    }

    public void setDeleteListener(DeleteListerner listener) {
        this.deleteListener = listener;
    }


}
